package com.shtel.bss.saas.tenant.controller;

import com.github.pagehelper.PageInfo;
import com.shtel.bss.saas.core.data.common.controller.DataController;
import com.shtel.bss.saas.tenant.bo.SysUserBo;
import com.shtel.bss.saas.tenant.dto.SysUserDTO;
import com.shtel.bss.saas.tenant.mapstrut.EntityDtoMapper;
import com.shtel.bss.saas.tenant.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户表 controller
 *
 * @author xiezhiwei 2020-02-05 22:03
 */
@RestController
@RequestMapping("sys/tenant/sysUser")
public class SysUserController extends DataController {
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询用户列表
     */
    @PostMapping("qrySysUserList")
    public PageInfo<SysUserDTO> qrySysUserList(@RequestBody SysUserDTO sysUserDTO) {
        PageInfo<SysUserBo> sysUserPageInfo = sysUserService.qrySysUserList(EntityDtoMapper.INSTANCE.toSysUserBo(sysUserDTO),
                sysUserDTO.getPageNum(),
                sysUserDTO.getPageSize());
        return EntityDtoMapper.INSTANCE.toSysUserPageInfo(sysUserPageInfo);
    }

    /**
     * 查询用户
     */
    @PostMapping("qrySysUser")
    public SysUserDTO qrySysUser(@RequestBody SysUserDTO sysUserDTO) {
        return EntityDtoMapper.INSTANCE.toSysUserDTO(sysUserService.qrySysUser(EntityDtoMapper.INSTANCE.toSysUserBo(sysUserDTO)));
    }

    /**
     * 保存用户
     *
     * @param sysUserDTO
     */
    @PostMapping("saveSysUser")
    public void saveSysUser(@RequestBody SysUserDTO sysUserDTO) {
        sysUserService.saveSysUser(EntityDtoMapper.INSTANCE.toSysUserBo(sysUserDTO));
    }

    /**
     * 修改用户
     *
     * @param userId
     * @param sysUserDTO
     */
    @PutMapping("updateSysUser/{userId}")
    public void updateSysUser(@PathVariable Long userId, @RequestBody SysUserDTO sysUserDTO) {
        sysUserService.updateSysUser(EntityDtoMapper.INSTANCE.toSysUserBo(sysUserDTO));
    }

    /**
     * 删除用户
     *
     * @param userId
     */
    @DeleteMapping("deleteSysUser/{userId}")
    public void deleteSysUser(@PathVariable Long userId) {
        sysUserService.removeSysUser(userId);
    }
}